package com.jdrx.ocp.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {
    public static boolean isThisWeek(Date time)
    {
        Calendar calendar = Calendar.getInstance();
        int currentWeek = calendar.get(Calendar.WEEK_OF_YEAR);
        calendar.setTime(time);
        int paramWeek = calendar.get(Calendar.WEEK_OF_YEAR);
        if(paramWeek==currentWeek){
            return true;
        }
        return false;
    }
    //是否是今天
    public static boolean isToday(Date time)
    {
        return isThisTime(time,"yyyy-MM-dd");
    }
    //是否是本月
    public static boolean isThisMonth(Date time)
    {
        return isThisTime(time,"yyyy-MM");
    }
    //是否是今年
    public static boolean isThisYear(Date time)
    {
        return isThisTime(time,"yyyy");
    }

    private static boolean isThisTime(Date time,String pattern) {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        String param = sdf.format(time);//参数时间
        String now = sdf.format(new Date());//当前时间
        if(param.equals(now)){
            return true;
        }
        return false;
    }
}
